{include file="common/head"/}
 
  <script src="//unpkg.com/jquery@3.3.1/dist/jquery.min.js"></script>
  <script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
  <script type="text/javascript" src="/static/ueditor/ueditor.all.js"></script> 
<style>
    .layui-text em, .layui-word-aux{
        color: red !important;
    }
</style>
<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">
    
    <fieldset class="layui-elem-field layui-field-title">
        <legend>添加</legend>
    </fieldset>

    <form class="layui-form layui-form-pane">

        <!-- 广告位置 S -->
        <div class="layui-form-item">
            <label class="layui-form-label">广告位置</label>
            <div class="layui-input-4">
                <select name="address_id" lay-verify="required">
                    <option value=""></option>
                    {foreach $bannerAddressList as $key=>$val }
                    <option value="{$val.id}">{$val.title}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux required">*</div>
        </div>
        <!-- 广告位置 E -->

        <!-- 标题 S -->
        <div class="layui-form-item">
            <label class="layui-form-label"> 标题 </label>
            <div class="layui-input-4">
                <input type="text" name="title" ng-model="field.title" lay-verify="required"  class="layui-input" autocomplete="off">
            </div>
            <div class="layui-form-mid layui-word-aux required">*</div>
        </div>
        <!-- 标题 E -->

        <!-- 排序 S -->
        <div class="layui-form-item">
            <label class="layui-form-label"> 排序 </label>
            <div class="layui-input-4">
                <input type="text" name="sort" ng-model="field.sort" class="layui-input"  placeholder="该项默认值是0" autocomplete="off">
            </div>
        </div>
        <!-- 排序 E -->

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>

    </form>
</div>
{include file="common/foot"/}

  <link href="/static/common/css/formSelects-v4.css" rel="stylesheet" />

<script src="/static/common/js/angular.min.js"></script>
<script>
    
   layui.config({
        base: '/static/common/js/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects-v4'
    });

    
  
    UE.getEditor('content',{
        initialFrameWidth : 600,
        initialFrameHeight: 600,
        
     });

    var m = angular.module('hd',[]);
    
    m.controller('ctrl',function($scope) {
        layui.use(['form','upload', 'layer','layedit','formSelects'], function () {
             var form = layui.form, layer = layui.layer,$= layui.jquery,upload = layui.upload,layedit = layui.layedit;
             
              
             var formSelects = layui.formSelects;
             formSelects.btns('city', []);
            

            form.on('submit(submit)', function (data) {

                // 提交到方法 默认为本身
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                
                 //获取编辑器的内容

                $.post("", data.field, function (res) {

                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            })

            
            var uploadInst = upload.render({ 
                elem: ".uploadImg" ,
                url: "{:url("UpFiles/upload")}" ,
                before: function(obj){
                  var _this = this;
                  obj.preview(function(index, file, result){
                       _this.item.parents(".fieldName").find("img").attr("src",result)
                  });  
                },
                done: function(res){ 
                    if(res.code>0){ 
                      this.item.parents(".fieldName").find("input[type=hidden]").val(res.url)
                    }else{ 
                      return layer.msg("上传失败");
                    } 
                } ,
                  error: function(res){ 
                    var demoText = this.item.parents(".fieldName").find(".demoText");
                     demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');  
                     demoText.find(".demo-reload").on("click", function(){  
                      uploadInst.upload(); 
                    });
                  }
            });

        });
    });



    // 时间插件shi-jian-cha-jian
    
useLayDateMultiple('begin_time');

useLayDateMultiple('end_time');

    function useLayDateMultiple(cls) {
        layui.use('laydate', function() {
            var laydate = layui.laydate;
            lay('#' + cls).each(function() {
                laydate.render({
                    elem : this,
                    trigger : 'click',
                    type : 'datetime'
                });
            });
        });
    }
</script>
</body>
</html>